﻿package com.diandong.airfieldmanage.main.home.manageMemo;

import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.diandong.airfieldmanage.R;
import com.diandong.airfieldmanage.base.BaseActivity;
import com.diandong.airfieldmanage.main.notify.adapter.SendEnclosureAdapter;
import com.diandong.airfieldmanage.utils.FileUtil;
import com.diandong.airfieldmanage.utils.LogUtil;
import com.diandong.airfieldmanage.utils.ToastUtil;
import com.diandong.airfieldmanage.widget.NoScrollGridView;
import com.diandong.airfieldmanage.widget.ScrollEditText;
import com.tbruyelle.rxpermissions2.RxPermissions;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import io.reactivex.functions.Consumer;

/**
 * Created : Yx
 * Time : 2019/9/5 10:43
 * Describe :
 */
public class AddMeetingActivity extends BaseActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_meeting);
        
        initRecyclerClick();

    }

    private void initRecyclerClick() {
        adapter.setOnItemClickListener(position -> {//按钮点击后
            RxPermissions rxPermissions = new RxPermissions(this);
            //是否有读写权限
            rxPermissions.request(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE).subscribe(new Consumer<Boolean>() {
                @Override
                public void accept(Boolean aBoolean) throws Exception {
                    if (aBoolean) {//授权成功
                        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                        intent.setType("*/*");//设置类型，我这里是任意类型，任意后缀的可以这样写。
                        intent.addCategory(Intent.CATEGORY_OPENABLE);
                        startActivityForResult(intent, 1);
                    } else {
                        ToastUtil.showToastApplication("请添加读写权限！");
                    }
                }
            });

        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1) {
            if (resultCode == RESULT_OK) {
                Uri uri = data.getData();
                if (uri != null) {
                    String path = UriPathUtils.getPath(this, uri);
                    if (path != null) {
                        File file = new File(path);
                        if (file.exists()) {
                            String upLoadFilePath = file.toString();
                            String upLoadFileName = file.getName();
                            LogUtil.iYx("----文件路径：" + upLoadFilePath);
                            LogUtil.iYx("----文件名称：" + upLoadFileName);
                            mList.add(mList.size() - 1, upLoadFileName);
                            adapter.notifyDataSetChanged();
                            //走上传接口、↓
                        }
                    }
                }
            }
        }
    }

}
